local PackageCell = class("PackageCell")
local TypeHelper = require("utils.TypeHelper")

local ITEM_NUM = 5

function PackageCell:ctor()
end

function PackageCell:awake()
end

function PackageCell:updateUI(lines)
    self._lines = lines
    for i = 1, ITEM_NUM do
        local data = lines[i]
        if data then
            local typeName = TypeHelper.getTypeName(data:getType())
            local updateFunc = self["_update_" .. typeName]
            if updateFunc then
                updateFunc(self, data, i)
            else
                self:_update_default(data, i)
            end
            self["_icon" .. i].gameObject:SetActive(true)
        else
            self["_icon" .. i].gameObject:SetActive(false)
        end
    end
end

function PackageCell:_update_default(data, index)
    self["_icon" .. index]:updateUI(data:getType(), data:getBase_id())
end

function PackageCell:_update_items(data, index)
    self["_icon" .. index]:updateUI(data:getType(), data:getBase_id(), data:getNum())
end

function PackageCell:_update_equipment(data, index)
    self["_icon" .. index]:updateUI(data:getType(), data:getBase_id())
end

function PackageCell:_update_hero(data, index)
    self["_icon" .. index]:setCallback(
        function()
            if not self._lines then
                return
            end
            local train = require("view.hero.HeroTrainView").new(self._lines[index])
        end
    )
    self["_icon" .. index]:updateUI(data:getType(), data:getBase_id())
end

return PackageCell
